<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
	<ui:composition template="/templates/padraoJSF.xhtml">
		<ui:define name="barraTitulo">Cadastro de Turma</ui:define>
		<ui:define name="conteudo"> 
			<h:form id="form">
				<p:growl id="messages"/>
				<fieldset>
					<p:tabView>
						<p:tab title="Cadastro">
							<h:panelGrid columns="2" columnClasses="alinhaDir" >
								<h:column >
								</h:column>
								<h:column >
									<h:outputText value="Os campos com asterisco (*) s&atilde;o de preenchimento obrigat&oacute;rio." styleClass="campoObrigatorio" />
								</h:column>
								<h:column >
									<h:outputLabel value="Curso:" styleClass="select" />
								</h:column>
								<h:column >
									<h:selectOneMenu value="#{controleTurma.turma.curso}">
					                    <f:selectItem itemLabel="selecione" itemValue="#{controleTurma.cursoSelecione}"/>
					                    <f:selectItems value="#{controleTurma.cursos}" var="curso" itemLabel="#{curso.descricao}" itemValue="#{curso}"/>
					                    <p:ajax listener="#{controleTurma.atualizarGradeCurricular}" update="gradeCurricular" />
					                    <f:converter converterId="converteCurso"/>
									</h:selectOneMenu>
									<h:outputText value="(*)" styleClass="campoObrigatorio" />
								</h:column>
								<h:column >
									<h:outputLabel value="Grade Curricular:" styleClass="select" />
								</h:column>
								<h:column >
									<h:selectOneMenu value="#{controleTurma.turma.gradeCurricular}" id="gradeCurricular">
					                    <f:selectItem itemLabel="selecione" itemValue="#{controleTurma.gradeCurricularSelecione}"/>
					                    <f:selectItems value="#{controleTurma.gradesCurricular}" var="gradeCurricular" itemLabel="#{gradeCurricular.descricao}" itemValue="#{gradeCurricular}"/>
					                    <f:converter converterId="converteGradeCurricular"/>
					                    <p:ajax listener="#{controleTurma.criaListaPeriodos}" update="periodo" />
									</h:selectOneMenu>
									<h:outputText value="(*)" styleClass="campoObrigatorio" />
								</h:column>
								<h:column >
									<h:outputLabel value="Descri&ccedil;&atilde;o:"/>
								</h:column>
								<h:column>
									<h:inputText size="80" maxlength="100" value="#{controleTurma.turma.descricao}" styleClass="upper" />
									<h:outputText value="(*)" styleClass="campoObrigatorio" />&nbsp;
								</h:column>									
								<h:column >
									<h:outputLabel value="Tipo:" styleClass="select" />
								</h:column>
								<h:column > 
									<h:selectOneMenu value="#{controleTurma.turma.tipo}"
													 immediate="true"	 
									                 valueChangeListener="#{controleTurma.crialistaDisciplinas}">  
					                    <f:selectItems value="#{controleTurma.tipos}" var="tipo" itemLabel="#{tipo}" itemValue="#{tipo}"/>
					                    <p:ajax event="change" update="gdr"/>
									</h:selectOneMenu>
									<h:outputText value="(*)" styleClass="campoObrigatorio" />&nbsp;
									
									<h:outputLabel value="Per&iacute;odoo:"/>&nbsp;
									<h:selectOneMenu value="#{controleTurma.turma.periodo}" id="periodo" >
					                    <f:selectItems value="#{controleTurma.periodos}" var="periodo" itemLabel="#{periodo}" itemValue="#{gradeCurricular}"/>
									</h:selectOneMenu>  
									
									<h:outputLabel value="Turma:"/>&nbsp;
									<h:inputText size="2" maxlength="2" value="#{controleTurma.turma.tipoTurma}" styleClass="upper" />
									<h:outputText value="(*)" styleClass="campoObrigatorio" />&nbsp;

									<h:outputLabel value="Turno:" styleClass="select" />
									<h:selectOneMenu value="#{controleTurma.turma.turno}">  
					                    <f:selectItems value="#{controleTurma.turnos}" var="turno" itemLabel="#{turno}" itemValue="#{turno}"/>
									</h:selectOneMenu>
									<h:outputText value="(*)" styleClass="campoObrigatorio" />&nbsp;
								</h:column>
								<h:column >
								</h:column>
								<h:column >
									<h:outputLabel value="Verifica Pagamento na Matr&iacute;cula:" />&nbsp;
									<h:selectBooleanCheckbox value="#{controleTurma.turma.checkPagamento}" />&nbsp;
									<h:outputLabel value="Gera Boleto:" />&nbsp;
									<h:selectBooleanCheckbox value="#{controleTurma.turma.geraBoleto}" />&nbsp;
								</h:column>
							</h:panelGrid>
						</p:tab>
					</p:tabView>
				</fieldset>
				<fieldset>
					<p:panel>
						<h:outputLabel value="Adiciona Oferta de Turma"/>
						<br></br>
						<h:panelGrid columns="2" columnClasses="alinhaDir width60" >
							<h:column >
							</h:column>
							<h:column>
								<h:outputLabel value="Ano:"/>
								<h:inputText size="4" maxlength="4" value="#{controleTurma.ano}" />&nbsp;
								<h:outputLabel value="Semestre:"/>
								<h:inputText size="2" maxlength="2" value="#{controleTurma.semestre}" />&nbsp;
								<h:outputLabel value="Vagas:"/>
								<h:inputText size="4" maxlength="4" value="#{controleTurma.vagas}" />&nbsp;
								<h:panelGroup id="gdr">
									<h:column>
										<h:outputLabel value="Disciplina:" styleClass="select" rendered="#{controleTurma.turma.tipo == 'Especial'}" />
									</h:column>
									<h:column >								
										<h:selectOneMenu value="#{controleTurma.disciplina}" rendered="#{controleTurma.turma.tipo == 'Especial'}">  
						                    <f:selectItems value="#{controleTurma.disciplinas}" var="disciplina" itemLabel="#{disciplina.descricao}" itemValue="#{disciplina}"/>
						                    <f:converter converterId="converteDisciplina"/>
										</h:selectOneMenu>
									</h:column>
								</h:panelGroup>
							</h:column>	
							<h:column >
							</h:column>
							<h:column >
								<p:commandLink action="#{controleTurma.addTurmaOferta}" id="cmdLinkAddOfertaDisciplina" update=":form">
									<h:graphicImage url="/images/botoes/btnAdicionar.png" styleClass="imageField alinhaBotao"/>
								</p:commandLink>
							</h:column>
						</h:panelGrid>
					</p:panel>
				</fieldset>				
				<fieldset>
					<p:accordionPanel multiple="true" activeIndex="#{controleTurma.acordionIndex}" >
						<c:forEach var="turmaOferta" items="#{controleTurma.turma.turmaOferta}" varStatus="acordion">
							<p:tab  title="#{turmaOferta.ano} - #{turmaOferta.semestre}">
								<table>
									<tr class="titulo">
										<td class="width30 alinhaMeio">Ano</td>
										<td class="width30 alinhaMeio">Semestre</td>
										<td class="width30 alinhaMeio">Vagas</td>
										<td class="width30 alinhaMeio">A&ccedil;&otilde;es</td>
									</tr>
									<c:if test="#{corTabela != 'corUm'}" var="controleCor">
										<c:set var="corTabela" value="corUm"></c:set>
									</c:if>
									<c:if test="#{corTabela != 'corDois' and controleCor == false}">
										<c:set var="corTabela" value="corDois"></c:set>
									</c:if>
									<tr class="#{corTabela}">
										<td class="alinhaEsq width40">
											<h:outputText value="#{turmaOferta.ano}"/>
										</td>
										<td class="alinhaEsq width40">
											<h:outputText value="#{turmaOferta.semestre}"/>
										</td>
										<td class="alinhaEsq width40">
											<h:outputText value="#{turmaOferta.vagas}"/>
										</td>
										<td class="alinhaMeio">
											<p:commandLink action="#{controleTurma.removeTurmaOferta}" update=":form">
												<h:graphicImage url="/images/marcadores/remove.png" styleClass="iconesLaterais"/>
												<f:setPropertyActionListener target="#{controleTurma.turmaOferta}" value="#{turmaOferta}" />
											</p:commandLink>
										</td>
									</tr>
									<tr>
										<td colspan="4">
											<fieldset>
												<table>
													<tr>
														<td></td>
														<td></td>
													</tr>
													<tr>
														<td>&nbsp;</td>
														<td></td>
													</tr>
													<tr>
														<td class="alinhaDir">&nbsp;</td>
														<td>
															<div id="gradeDisciplina">
																<div id="periodoDisciplinas">
																	<ui:repeat var="turmaOfertaDisciplina" value="#{turmaOferta.turmaOfertaDisciplina}">
																		<div class="barrTopoTabelas">
																			<span>
																				<h:outputText value="#{turmaOfertaDisciplina.disciplina.codigoDisciplina}"/>
																				<h:outputText value=" - "/>
																				<h:outputText value="#{turmaOfertaDisciplina.disciplina.descricao}"/>
																			</span>
																			<h:commandLink value="" rendered="#{controleTurma.turma.curso.tipoCurso.codigoTipoCurso == 1}">
																				<h:graphicImage url="/images/botoes/btnAddHorario.png" onclick="modalPsqHorario.show();" styleClass="iconesLaterais" />
																				<f:setPropertyActionListener target="#{controleTurma.turmaOfertaDisciplina}" value="#{turmaOfertaDisciplina}"  />
																				<f:setPropertyActionListener target="#{controleTurma.acordionIndex}" value="#{acordion.count}"  />
																				<p:ajax update=":form"/>
																			</h:commandLink>
																			<h:commandLink value="">
																				<h:graphicImage url="/images/botoes/btnAdicionarProfessor.png" onclick="modalPsq.show();" styleClass="iconesLaterais" />
																				<f:setPropertyActionListener target="#{controleTurma.turmaOfertaDisciplina}" value="#{turmaOfertaDisciplina}" />
																				<f:setPropertyActionListener target="#{controleTurma.acordionIndex}" value="#{acordion.count}"  />
																				<p:ajax update=":form"/>
																			</h:commandLink>
																		</div>
																		<div>
																			<p:panel rendered="#{not empty turmaOfertaDisciplina.professorDisciplina}">
																				<table class="tabelaProfessor">
																					<tr>
																						<td></td>
																						<td class="width100"></td>
																					</tr>
																					<tr class="titulo">
																						<td>Professor</td>
																						<td class="alinhaMeio">Carga Hor&aacute;ria</td>
																						<td class="alinhaMeio">A&ccedil;&otilde;es</td>
																					</tr>
																					<ui:repeat var="professorDisciplina" value="#{turmaOfertaDisciplina.professorDisciplina}">
																						<tr class="corDois">
																							<td><h:outputText value="#{professorDisciplina.professor.pessoa.nome}"/></td>
																							<td class="alinhaMeio">
																								<h:inputText size='2' maxlength='2' value="#{professorDisciplina.cargaHoraria}" />
																							</td>
																							<td class="alinhaMeio width50">
																								<p:commandLink action="#{controleTurma.removeProfessorDisciplina}" update=":form">
																									<h:graphicImage url="/images/marcadores/remove.png" alt="Remove Professor" styleClass="iconesLaterais"/>
																									<f:setPropertyActionListener target="#{controleTurma.professorDisciplina}" value="#{professorDisciplina}" />
																								</p:commandLink>																						
																							</td>
																						</tr>
																					</ui:repeat>
																				</table>
																			</p:panel>
																		</div>
																	</ui:repeat>
																</div>
																<!-- Horario  -->
																<c:if test="#{controleTurma.turma.curso.tipoCurso.codigoTipoCurso == 1}" >
																	<c:if test="${not empty turmaOferta.turmaOfertaDisciplina}">
																		<fieldset>
																			<legend>Hor&aacute;rio</legend>
																			<table>
																				<tr>
																					<td class="width40"></td>
																					<td class="width60"></td>
																					<td class="width60"></td>
																					<td class="width60"></td>
																					<td class="width60"></td>
																					<td class="width60"></td>
																					<td class="width60"></td>
																					<td class="width60"></td>
																				</tr>
																				<tr class="titulo">
																					<td class="alinhaMeio">Aula</td>
																					<td class="alinhaMeio">Seg</td>
																					<td class="alinhaMeio">Ter</td>
																					<td class="alinhaMeio">Qua</td>
																					<td class="alinhaMeio">Qui</td>
																					<td class="alinhaMeio">Sex</td>
																					<td class="alinhaMeio">Sab</td>
																					<td class="alinhaMeio">Dom</td>
																				</tr>
																				<c:forEach var="aula" begin="1" end="5" step="1">

																					<c:if test="#{corTabela != 'corUm'}" var="controleCor">
																						<c:set var="corTabela" value="corUm"></c:set>
																					</c:if>
																					<c:if test="#{corTabela != 'corDois' and controleCor == false}">
																						<c:set var="corTabela" value="corDois"></c:set>
																					</c:if>
																					<tr class="${corTabela}">
																						<td class="alinhaMeio">${aula}&ordf; </td>
																						<c:forEach var="dia" begin="1" end="7" step="1">
																							<td class="alinhaMeio">
																								<ui:repeat var="turmaOfertaDisciplina" value="#{turmaOferta.turmaOfertaDisciplina}">
																									<ui:repeat var="horario" value="#{turmaOfertaDisciplina.horarios}">
																										<h:outputText value="#{turmaOfertaDisciplina.disciplina.identificador}" rendered="#{horario.dia == dia and horario.aula == aula}"/>
																										<p:commandLink action="#{controleTurma.removeHorario}" update=":form" rendered="#{horario.dia == dia and horario.aula == aula}">
																											<h:graphicImage url="/images/marcadores/remove.png" styleClass="iconesLaterais"/>
																											<f:setPropertyActionListener target="#{controleTurma.horario}" value="#{horario}" />
																										</p:commandLink>																											
																									</ui:repeat>
																								</ui:repeat>
																							</td>
																						</c:forEach>
																					</tr>
																				</c:forEach>
																			</table>
																		</fieldset>													
																	</c:if>
																</c:if>
																<!-- Fim Horario  -->
															</div>
														</td>
													</tr>
												</table>
											</fieldset>
										</td>
									</tr>
								</table>
							</p:tab>
						</c:forEach>
					</p:accordionPanel>
				</fieldset>
				<h:outputLink value="manutencao.jsf">
					<h:graphicImage url="/images/botoes/btnPesquisar.png" class="btnAcoes"/>
				</h:outputLink>
				<h:commandLink action="#{controleTurma.gravar}" styleClass="alinhaDir">
					<h:graphicImage url="/images/botoes/btnGravar.png" class="btnAcoes"/>
				</h:commandLink>
			</h:form>
			<!-- Dialog Pesquisa Professor -->
			<p:dialog header="Adiciona Professor" width="600" height="400" widgetVar="modalPsq" modal="true" fixedCenter="true" effect="FADE">
				<h:form id="formPesquisa">
					<p:tabView id="tabView">
						<p:tab title="Pesquisa de Professor">
							<fieldset>
								<h:panelGrid columns="2" columnClasses="alinhaEsq width50">
									<h:column>
										<h:outputLabel value="Nome:" styleClass="textfield" />
									</h:column>
									<h:column>
										<h:inputText value="#{controleTurma.pesquisaNomeProfessor}"  size="70" styleClass="textfield" />
									</h:column>								
								</h:panelGrid>
							</fieldset>
							<p:commandLink actionListener="#{controleTurma.pesquisaProfessorNome}" styleClass="alinhaDir" update=":listaFormPesquisa">
								<h:graphicImage url="/images/botoes/btnPesquisar.png" class="btnAcoes"/>
							</p:commandLink>
						</p:tab>
					</p:tabView>
				</h:form>
				<h:form id="listaFormPesquisa">
					<p:dataTable value="#{controleTurma.listaProfessores}" 
					             id="id_ListaProfessor"
					             var="professor" 
					             paginator="true" 
					             rows="10" 
					             dynamic="true" 
					             rendered="#{not empty controleTurma.listaProfessores}" 
								 firstPageLinkLabel="Primeiro"
					             previousPageLinkLabel="Anterior"
					             nextPageLinkLabel ="Pr&oacute;ximo"
					             lastPageLinkLabel="&Uacute;ltima"
					             emptyMessage="Nenhum resgistro encontrado"
					             errorMessage="Ocorreu um erro"
	    			             selection="#{controleTurma.professor}" 
					             selectionMode="single" >
						<p:column styleClass="width60"  >
							<f:facet name="header">
								<h:outputText value="Codigo" />
							</f:facet>
							<h:outputText value="#{professor.codigoProfessor}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Nome" />
							</f:facet>
							<h:outputText value="#{professor.pessoa.nome}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="CPF" />
							</f:facet>
							<h:outputText value="#{professor.pessoa.CPF}">
								<f:converter converterId="converteCPF" />
							</h:outputText>
						</p:column>
						<p:column resizable="true" styleClass="width80">
							<f:facet name="header">
								<h:outputText value="A&ccedil;&atilde;o" /> 
							</f:facet>
                                 <h:commandLink action="#{controleTurma.addProfessor}">  
                                         <p:graphicImage url="/images/marcadores/editar.png" alt="Seleciona Professor"/>  
                                         <f:setPropertyActionListener target="#{controleTurma.professor}" value="#{professor}" />
                                 </h:commandLink>
                     	</p:column>						
					</p:dataTable>
				</h:form>
			</p:dialog>		
			<!-- Fim de Pesquisa Professor -->
			<!-- Dialog Adicionar Horario -->
			<p:dialog header="Adiciona Hor&aacute;rio" width="400" height="200" widgetVar="modalPsqHorario" modal="true" fixedCenter="true" effect="FADE">
				<h:form id="formAddHorario">
					<p:tabView id="tabView">
						<p:tab title="Hor&aacute;rio da Disciplina">
							<fieldset>
								<h:panelGrid columns="2" columnClasses="alinhaEsq width50">
									<h:column>
										<h:outputLabel value="Dia:" styleClass="textfield" />
									</h:column>
									<h:column>
										<h:selectOneMenu value="#{controleTurma.dia}">  
					                    	<f:selectItems value="#{controleTurma.dias}" var="dia" itemLabel="#{dia}" itemValue="#{dia}"/>
										</h:selectOneMenu>
										&nbsp;
										<h:outputLabel value="Aula:" styleClass="textfield" />&nbsp;
										<h:selectOneMenu value="#{controleTurma.aula}">  
					                    	<f:selectItems value="#{controleTurma.aulas}" var="aula" itemLabel="#{aula}" itemValue="#{aula}"/>
										</h:selectOneMenu>
									</h:column>								
								</h:panelGrid>
							</fieldset>
							<p:commandLink action="#{controleTurma.addHorario}" styleClass="alinhaDir" update=":form">
								<h:graphicImage url="/images/botoes/btnAdicionar.png" class="btnAcoes"/>
							</p:commandLink>									
						</p:tab>
					</p:tabView>
				</h:form>
			</p:dialog>
			<!-- Dialog Adicionar Horario -->
		</ui:define>
	</ui:composition>
</html>